import java.util.Random;
import java.util.Scanner;
class Animal{
    String name;
    int age;

    public void eat(){
        System.out.println(name + "正在吃饭");
    }
    public void sleep(){
        System.out.println(name + "正在睡觉");
    }
}

class Dog extends Animal{
    {
        this.name = "小黄";
    }
    void bark(){
        System.out.println(name + "汪汪汪~~~");
    }
}

class Cat extends Animal{
    {
        this.name = "小眯";
    }
    void mew(){
        System.out.println(name + "喵喵喵~~~");
    }
}

/*
class G{
    public int a = 10;
    public int b = 20;

    public void P(){
        System.out.println("我是父类");
    }
    public void P1(int i){
        System.out.println("我是父类");
    }
}

class A extends G{
    public int a = 30;
    public int c = 40;

    public void P(){
        System.out.println("我是子类");
    }
    public void P1(){
        System.out.println("我是子类");
    }
}
*/

/*class G{
    public int a = 10;

    public void P(){
        System.out.println("我是父类");
    }
}

class A extends G {
    public int a = 20;

    public void P() {
        super.P();      //访问父类方法P
        System.out.println("我是子类");
    }

    public void display() {
        System.out.println(super.a); // 访问父类的a变量    10
        System.out.println(this.a);    // 访问子类的a变量  20
    }
}*/

/*
class G{
    public G(){
        System.out.println("我是父类");
    }
}

class A extends G {
   public A(){
       super();
       System.out.println("我是子类");
   }
}
*/

/*class G{

    static {
        System.out.println("我是父类静态代码块");
    }

    {
        System.out.println("我是父类实例代码块");
    }

    public G(){
        System.out.println("我是父类构造方法");
    }
}

class A extends G {
    static {
        System.out.println("我是子类静态代码块");
    }

    {
        System.out.println("我是子类实例代码块");
    }

    public A(){
        System.out.println("我是子类构造方法");
    }
}*/
/*
final class A{
    //.......
}
class B extends A{
    //.......
}
class C extends A{
    //.......
}
*/

/*
class Tire{
    //轮胎....
}
class Engine{
    // 发动机...
}
class VehicleSystem{
    // 车载系统...
}
class Car{
    private Tire tire; // 可以复用轮胎中的属性和方法
    private Engine engine; // 可以复用发动机中的属性和方法
    private VehicleSystem vs; // 可以复用车载系统中的属性和方法
// ...
}
class Benz extends Car{
// 将汽车中包含的：轮胎、发送机、车载系统全部继承下来
}
*/

/*
class Base {

    private int x;
    private int y;

    public Base(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }


}
class Sub extends Base {

    private int z;

    public Sub(int x, int y, int z) {
        super(x,y);
        this.z = z;
    }

    public int getZ() {
        return z;
    }

    public int calculate() {
        return super.getX() * super.getY() * this.getZ();
    }

}
*/


/*
class X{
    Y y=new Y();//1
    public X(){//2
        System.out.print("X");
    }
}
class Y{
    public Y(){//3
        System.out.print("Y");
    }
}

class Z extends X {
    Y y = new Y();//4

    public Z() {//5
        System.out.print("Z");
    }
}
*/
/*class A{

    public int Add(int x){
        return x;
    }
    public int Add(int x,int y){
        return x + y;
    }
    public int Add(int x,int y,int z){
        return x + y + z;
    }
}*/
/*
class Shape {
    //属性....
    public void draw() {
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("♦");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("●");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀");
    }
}
class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("△");
    }
*/



/*
class A {
    int x;
    int y;

    public A(int x,int y){
        this.x = x;
        this.y = y;
    }
}

class B extends A
{
    int z;

    public B(int x,int y,int z){
        super(x,y);
        this.z = z;
    }
}
*/



/*
class Animal {
    public  String name;
    public int age;
    public Animal(String name, int age){
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name + "吃饭");
    }
}

class Cat extends Animal{
    public Cat(String name, int age){
        super(name, age);
    }
    @Override
    public void eat(){
        System.out.println(name+"吃鱼~~~");
    }
}

class Dog extends Animal {
    public Dog(String name, int age){
        super(name, age);
    }
    @Override
    public void eat(){
        System.out.println(name+"吃骨头~~~");
    }
}
*/

public class Test {



    public static void main(String[] args) {

        /*//向上转型，父类的引用指向了子类
        //animal的编译类型是Animal，运行类型是Dog
        Animal animal = new Dog();

        animal = new Cat();
        //animal的运行类型变成了Cat，编译类型任然是Animal


        Dog d = (Dog) animal;
        d.bark();//这里我们就可以调用Dog类中方法*/


        //向上转型
        Animal animal = new Dog();

        //判断instanceof 是否为 true
        if(animal instanceof Dog) {
            //向下转型
            animal = (Dog)animal;
            ((Dog) animal).eat();
        } else {
            System.out.println("Animal无法向下转型为Dog");
        }












/*
        Shape[] shapes = {new Cycle(), new Rect(), new Cycle(),
                new Rect(), new Flower()};
        for (Shape shape : shapes) {
            shape.draw();
        }
*/

       /* Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }*/













       /* Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int z = scanner.nextInt();
            Sub sub = new Sub(x, y, z);
            System.out.println(sub.calculate());*/



        /*A f1 = new A();


        System.out.println("====================================================================");
        A f2 = new A();
*/


       /* A f = new A();
        System.out.println(f.a); //子类父类中都有a，遵循就近原则，这个a为子类的a
        System.out.println(f.b);//子类没有b父类有b，这个b为父类的b
        System.out.println(f.c);//父类没有c子类有c，这个c为子类的c
        f.P();//子类父类中都有方法P，遵循就近原则，这个方法为子类的方法
        f.P1();//父类没有无参的方法P1子类有无参的方法P1，这个方法为子类的方法
        f.P1(1);//子类没有带一个参的方法P1子类没有带一个参的方法P1，这个方法为父类的方法
*/


        /*Dog dog = new Dog();
        dog.eat();
        dog.sleep();
        dog.bark();
        System.out.println("====================================================================");
        Cat cat = new Cat();
        cat.eat();
        cat.sleep();
        cat.mew();*/

    }
}
